﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YArchitech.LIB;

namespace HYOpeningDetail
{
	internal class PointBasedComponent : Component
	{
		public void DimBoxFunction(ElementInfo elementInfo, ViewPlan viewPlan, Dictionary<XYZ, DataWall> dicWallCurve, Dictionary<XYZ, List<Curve>> dicCombineGridCurve, Autodesk.Revit.DB.Document doc, int iBoxCategory)
		{
			this.m_doc = doc;
			Transaction transaction = new Transaction(this.m_doc, "Dim");
			try
			{
				transaction.Start();
				this.CreateLeaderDimension(elementInfo, viewPlan, iBoxCategory);
				transaction.Commit();
			}
			catch (Exception)
			{
				transaction.RollBack();
			}
		}

		public bool CreateLeaderDimension(ElementInfo elementInfo, ViewPlan viewPlan, int iBoxCategory)
		{
			FamilyInstance familyInstance = elementInfo.element as FamilyInstance;
			LocationPoint locationPoint = familyInstance.Location as LocationPoint;
			XYZ xyz;
			if (elementInfo.revitLink != null)
			{
				xyz = elementInfo.revitLink.GetTransform().OfPoint(locationPoint.Point);
			}
			else
			{
				xyz = locationPoint.Point;
			}
			string strLevelText = null;
			string strFamText = null;
			this.GetDimText(familyInstance, iBoxCategory, ref strLevelText, ref strFamText);
			XYZ xyz2 = xyz;
			XYZ ptDimPosionFir = new XYZ(xyz2.X + NumbericTools.mmToFeet(800.0), xyz2.Y - NumbericTools.mmToFeet(400.0), xyz2.Z);
			base.LeaderDimension(xyz2, ptDimPosionFir, strFamText, strLevelText, viewPlan);
			return true;
		}

		private void GetDimText(FamilyInstance familyInstance, int iBoxCategory, ref string strLevelText, ref string strFamText)
		{
			string text = null;
			string str = null;
			Parameter parameter = base.GetParameter(familyInstance, "标注标高");
			Parameter parameter2 = base.GetParameter(familyInstance, "标注内容");
			if (parameter != null)
			{
				text = parameter.AsString();
			}
			if (parameter2 != null)
			{
				str = parameter2.AsString();
			}
			string str2 = familyInstance.Symbol.Family.Name.ToString();
			strFamText = str2 + str;
			strLevelText = text;
		}
	}
}
